require('../../css/jeui/skin/jedate.css')
require('./index.less');
import $ from 'jquery';
$(function() {
    var group_tourist_json = { "id": "1", "jsonrpc": "2.0", "method": "getPartnerList", "params": { "pageNum": 1 } };
    var touristdata = $.ajax({
        contentType: "application/json;charset=utf-8",
        url: "/api/partnerApi",
        data: JSON.stringify(group_tourist_json),
        type: "post",
        dataType: "json"
    });
    touristdata.then(function(data) {
        for (var i = 0; i < data.result.body.length; i++) {
            var tdata = data.result.body[i];
            $("#partnerID").append("<option value='" + tdata.id + "'>" + tdata.name + "</option>");
        }
    })
    $(".serch-btn").click(function() {
        var order_data_json = { "id": "1", "jsonrpc": "2.0", "method": "getReserveOrderList", "params": { "type": "1", "transactionTypeId": "", "saleTypeId": "", "orderType": "", "partnerId": $("#partnerID").val(), "playStartrDate": $("#inpstart").val(), "playEndDate": $("#inpend").val() } };
        var grouporderdata = $.ajax({
            contentType: "application/json;charset=utf-8",
            url: "/api/baseInfoApi",
            data: JSON.stringify(order_data_json),
            type: "post",
            dataType: "json"
        });
        grouporderdata.then(function(data) {
            $(".serch_all").empty();
            if (data.result.body == "SUCCESS") {
                $(".je-table").hide();
                $(".success").show();
            } else {
                $(".je-table").show();
                $(".success").hide();
                for (var i = 0; i < data.result.body.length; i++) {
                    var odata = data.result.body[i];
                    odata.status = getstate(data.result.body[i].state);
                    odata.playdate = formattime(data.result.body[i].playdate)
                    var serchtable = $("#serch_all").html();
                    var conReg = /(?:\{)(\w*)(?:\})/g;
                    var olisthtml = serchtable.replace(conReg, function(node, key) {
                        return odata[key];
                    });
                    $(".serch_all").append(olisthtml);
                }
            }

        })
    })
})

function getstate(n) {
    switch (n) {
        case 0:
            return "正常";
            break;
        case 1:
            return "作废";
            break;
        case 2:
            return "已出票";
            break;
        case 3:
            return "已检票";
            break;
        case 4:
            return "退票";
            break;
        default:
            return "正常";
            break;
    }
};

function formattime(date) {
    return date.substr(0, 10);
}